package com.nike.controller;

import com.jfinal.plugin.activerecord.Page;
import com.nike.model.Producttype;
import com.nike.router.RouterMapping;
import com.nike.utils.StringUtils;

/**
 * 商品分类
 * 
 * @author wuhantao
 *
 */
@RouterMapping(url = "/productType", viewPath = "/view/productType")
public class ProductTypeController extends BaseController<Producttype> {
	// 列表
	public void index() {
		String pageNumber = getPara("pageNumber");
		// 如果pageNumber为空，就默认为第1页
		if (!StringUtils.isNotBlank(pageNumber)) {
			pageNumber = "1";
		}
		Page<Producttype> page = Producttype.DAO.doPaginate(StringUtils.toInt(pageNumber, 1), 10);
		setAttr("page", page);
		render("list.html");
	}

	public void toAdd() {
		render("add.html");
	}

	public void insert() {
		Producttype producttype = getModel(Producttype.class, "ProductType");
		saved(producttype);
		redirect("/productType");
	}

	public void delete() {
		String id = getPara("id");
		Producttype.DAO.deleteById(id);
		redirect("/productType");
	}

}
